import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class drom101 {
    private String Sname;
    private String BuiltNum;
    private String DormNum;
    private String BedNum;

    public String getSname() {
        return Sname;
    }

    public void setSname(String sname) {
        Sname = sname;
    }

    public String getBuiltNum() {
        return BuiltNum;
    }

    public void setBuiltNum(String builtNum) {
        BuiltNum = builtNum;
    }

    public String getDormNum() {
        return DormNum;
    }

    public void setDormNum(String dormNum) {
        DormNum = dormNum;
    }

    public String getBedNum() {
        return BedNum;
    }

    public void setBedNum(String bedNum) {
        BedNum = bedNum;
    }

    @Override
    public String toString() {
        return "drom101{" +
                "Sname='" + Sname + '\'' +
                ", BuiltNum='" + BuiltNum + '\'' +
                ", DormNum='" + DormNum + '\'' +
                ", BedNum='" + BedNum + '\'' +
                '}';
    }

    public static List<drom101> GetInforDrom() throws Exception{
        String driverName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/ckr";
        String username = "root";
        String password = "1234";
        PreparedStatement pstmt;
        ResultSet rs;
        Connection conn = JDBC1.getConnection(driverName, url, username, password);
        String sql="select * from sdorm";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        List<drom101> list = new ArrayList<drom101>();
        while(rs.next()){
            drom101 d = new drom101();
            d.Sname = rs.getString("Sname");
            d.BuiltNum = rs.getString("BuiltNum");
            d.DormNum = rs.getString("DormNum");
            d.BedNum = rs.getString("BedNum");
            list.add(d);
        }
        return list;
    }
    //根据学生姓名查找该学生相关信息
    public static drom101 find3(String Sname)throws Exception{
        String driverName = "com.mysql.cj.jdbc.Driver";
        String url="jdbc:mysql://localhost:3306/ckr";
        String user = "root";
        String password = "1234";
        PreparedStatement stmt;
        ResultSet rs;
        Connection coon=JDBC1.getConnection(driverName,url,user,password);
        String sql="SELECT * FROM sdorm WHERE Sname=?";
        stmt=coon.prepareStatement(sql);
        stmt.setString(1,Sname);
        rs=stmt.executeQuery();
        drom101 d = new drom101();
        while(rs.next()){
            d.Sname = rs.getString("Sname");
            d.BuiltNum = rs.getString("BuiltNum");
            d.DormNum = rs.getString("DormNum");
            d.BedNum = rs.getString("BedNum");
        }
        return d;
    }
}
